<template>
    <!-- Main content -->
    <div>
        <div class="row">
            <div class="container-fluid">
                <theme-box title="电子券维护">
                    <form class="form-inline" @submit.prevent v-el:form>
                        <form-select title="商户号" :up-table="true" :sreach="true" name="mchtId"
                                     :options="mchtList"></form-select>
                        <form-input title="电子券名称" :up-table="true" name="name" :sreach="true" id="name"></form-input>
                        <form-select title="类型" :sreach="true" :up-table="true" name="type"
                                     :options="typeOptions"></form-select>
                        <span class="pull-right">
                            <button type="reset" @click="reset" class="btn btn-warning pull-right">重置</button>
                            <v-button theme="primary" @click="search" class="pull-right">查询</v-button>
                        </span>
                    </form>
                    <table class="table table-bordered table-striped" style="width:100%" v-el:table></table>
                </theme-box>
            </div>
            <!-- /.col -->
        </div>
        <modal-container title="修改" v-el:modal v-ref:modal class="edit-modal" theme="big">
            <form @submit.prevent @reset.prevent v-el:mform>
                <div class="edit-body modal-body">
                    <table-modal :item="item" :columns-set="columnsSet" v-ref:item></table-modal>
                </div>

                <div class="modal-footer">
                    <v-button data-dismiss="modal" @click="resetBindDrag">关闭</v-button>
                    <v-button theme="primary" type="submit" class="pull-right">保存</v-button>
                </div>
            </form>

        </modal-container>
        <modal-container title="详情" v-el:detail-modal v-ref:detail-modal class="edit-modal">
            <form @submit.prevent @reset.prevent v-el:detail-mform>
                <div class="modal-body">
                    <!-- <table-modal :item="item" :columns-set="columnsDetailSet"></table-modal> -->
                    <table class="table table-bordered table-hover">
                        <tr>
                            <td style="width:50%">商户名称</td>
                            <td>{{item.mchtName}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">电子券号</td>
                            <td>{{item.couponId}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%;">电子券名称</td>
                            <td style="word-wrap:break-word;word-break:break-all;">{{item.name}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">适用商户</td>
                            <td>{{item.mchtIds}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">类型</td>
                            <td>
                                {{ (item.type == 'rebate' && '折扣券') || (item.type == 'voucher' && '抵用券') || (item.type == 'cash' && '代金券') || (item.type == 'present' && '礼品券') || (item.type == 'ticket' && '票务')}}
                            </td>
                        </tr>
                        <tr v-show="item.restricted != 0">
                            <td style="width:50%">抵用券限制金额</td>
                            <td>{{item.restricted}}</td>
                        </tr>
                        <tr v-show="item.type !='rebate'">
                            <td style="width:50%">面值</td>
                            <td>{{item.denomination}}</td>
                        </tr>
                        <tr v-show="item.type =='rebate'">
                            <td style="width:50%">面值(90代9折)</td>
                            <td>{{item.denomination}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">营销规则</td>
                            <td>{{item.marketRule}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">营销结算规则</td>
                            <td>{{item.settRule}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">电子券状态</td>
                            <td>
                                {{(item.type2 == 'default' && '出售、分享、使用') || (item.type2 == 'share' && '分享、使用') || (item.type2 == 'useonly' && '使用')}}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%">发券途径</td>
                            <td>
                                {{(item.promAppro == 'general' && '普通券') || (item.promAppro == 'prom' && '推广券') || (item.promAppro == 'reward' && '打赏券') || (item.promAppro == 'buy' && '购买')}}
                            </td>
                        </tr>
                        <tr v-show="item.cash != 0">
                            <td style="width:50%">现金</td>
                            <td>
                                {{(item.cash)}}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%">授权商户</td>
                            <td>
                                {{(item.grantMerchant)}}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%">总数量</td>
                            <td>{{item.num}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">芸券估值</td>
                            <td>{{item.valuation}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">评估价值</td>
                            <td>{{item.worth}}</td>
                        </tr>
                        <!--<tr>-->
                        <!--<td style="width:50%">人均消费</td>-->
                        <!--<td>{{item.per}}</td>-->
                        <!--</tr>-->
                        <tr v-show="scpoe">
                            <td style="width:50%">适用范围</td>
                            <td>{{scpoe}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">已授权数量</td>
                            <td>{{issuedNum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">已出售数量</td>
                            <td>{{item.soldnum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">剩余数量</td>
                            <td>{{surplusnum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">已使用数量</td>
                            <td>{{item.usednum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">未使用数量</td>
                            <td>{{item.unusernum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">状态</td>
                            <td>{{item.status == "0" ? "正常" : "关闭"}}</td>
                        </tr>
                        <tr v-show="item.useRule">
                            <td style="width:50%">使用规则</td>
                            <td>{{useRule}}</td>
                        </tr>
                        <tr v-show="item.useNum">
                            <td style="width:50%">叠加张数</td>
                            <td>{{item.useNum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">第三方券类型</td>
                            <td>{{item.couponType == 'default' ? '默认' : '第三方'}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">使用描述类型</td>
                            <td>{{item.thirdType == 'default' ? '默认' : '链接'}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">第三方描述</td>
                            <td style="word-wrap:break-word;word-break:break-all;">{{item.thirdDesc}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">使用时间段</td>
                            <td>{{item.useTime}}</td>
                        </tr>
                        <tr v-show="item.disableDate">
                            <td style="width:50%">不可用日期</td>
                            <td>{{disableDate}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">有效开始日期</td>
                            <td>{{item.validatyBegin}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">有效结束日期</td>
                            <td>{{item.validatyEnd}}</td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <v-button class="pull--left" data-dismiss="modal" @click="resetBindDrag">关闭</v-button>
                </div>
            </form>
        </modal-container>
        <map :columns-set="map"></map>
        <!-- /.row -->
    </div>
    <!-- /.content -->
</template>

<style lang="less" scoped>
    .form-inline .btn + .btn {
        margin-right: 10px;
    }

    .form-inline .form-group + .form-group {
        margin-left: 20px;
    }
</style>
<style>


    #btn {
        height: 35px;
        background-color: #3c8dbc;
        border-width: 0px;
        color: #fff;
        text-align: center;
        border-radius: 3px;
    }

    .red {
        color: red;
    }
</style>
<script>
    //解决datatables弹窗警告
    $.fn.dataTable.ext.errMode = 'none';
    import {
        dateTime,
        createDataTable
    } from 'ui/collections/general.js'
    import {dateFormat} from "lib/method.js"
    import {dateTransform} from "lib/method.js"

    var serialize = require('form-serialize');

    var dataTable;
    var columnsSet;
    var columnsAuthorizeSet;
    export default {
        data: () => ({
            mchtIdent: '',
            eleNum: '',
            over: '',
            repName: '',
            strId: '',
            strNum: '',
            couponType: '',
            promTpe: '',
            scpoe: "",
            issuedNum: "",
            disableDate: "",
            useTime: "",
            useRule: "",
            surplusnum:"",
            item: {},
            mchtList: [],
            columnsSet: [],
            columnsAuthorizeSet: [],
            checkboxOptions: [],
            typeOptions: [
                {key: "所有类型", value: ""},
                {key: "折扣券", value: "rebate"},
                {key: "抵用券", value: "voucher"},
                {key: "代金券", value: "cash"},
                {key: "礼品券", value: "present"},
                {key: "票务", value: "ticket"}
            ],
            disableDay: [
                {key: "星期一", value: "1"},
                {key: "星期二", value: "2"},
                {key: "星期三", value: "3"},
                {key: "星期四", value: "4"},
                {key: "星期五", value: "5"},
                {key: "星期六", value: "6"},
                {key: "星期日", value: "7"},
            ],
            scopeTpe:'',
            rangeArr:[],
            marketArr:[],
            settArr:[]
        }),
        methods: {
            //还原弹出框位置
            resetBindDrag () {
                this.$refs.modal._resetBindDrag();
            },
            //查询按钮
            search: function () {
                dataTable.ajax.reload();
            },
            //详情按钮
            // details: function() {
            //     dataTable.ajax.reload();
            // },
            //重置按钮
            reset: function () {
                $(".form-inline")[0].reset();
                dataTable.ajax.reload();
            },
            getMcht (data) {
                let self = this;
                var mchtId = JSON.parse(localStorage.getItem("id_token")).mchtId
                self.$post({
                    url: "/api/v2" + projectName_Url + "/list/mcht/" + mchtId,
                    method: "GET"
                }).then(response => {
                    let list = response.content.info;
                    if (list.length == 1) {
                        list.unshift({key: "商户", value: ""});
                        self.$set("mchtList", list);
                    } else {
                        list.unshift({key: "所有商户", value: ""});
                        self.$set("mchtList", list);
                        self.mchtIdValue = list[0].value
                    }
                }, error => {
                });
            }
        },
        created () {
            //主页面datatable所用数组
            columnsSet = [{
                title: "商户号",
                data: "mchtId",
                visible: false,
                className: "operate"
            }, {
                title: "商户名称",
                data: "mchtName",
                edit: true,
                readonly: true,
                className: "operate"
            }, {
                title: "电子券号",
                data: "couponId",
                edit: true,
                readonly: true,
                visible: false,
                className: "operate"
            }, {
                title: "电子券名称",
                data: "name",
                edit: true,
                className: "wrap"
            }, {
                title: "适用商户",
                data: "mchtIds",
                visible: false,
                className: "operate"
            }, {
                title: "类型",
                data: "type",
                className: "operate",
                options: [
                    {key: "折扣券", value: "rebate"},
                    {key: "抵用券", value: "voucher"},
                    {key: "代金券", value: "cash"},
                    {key: "礼品券", value: "present"},
                    {key: "票务", value: "ticket"},
                ],
                render: function (data) {
                    var value;
                    if (data == "rebate") {
                        value = '折扣券'
                    } else if (data == "voucher") {
                        value = '抵用券'
                    } else if (data == "cash") {
                        value = "代金券"
                    } else if (data == "present") {
                        value = "礼品券"
                    } else {
                        value = "票务"
                    }
                    return value;
                }
            }, {
                title: "抵用券限制金额",
                data: "restricted",
                edit: false,
                className: "operate"
            }, {
                title: "面值",
                data: "denomination",
                edit: true,
                className: "operate"
            }, {
                title: "面值(90代9折)",
                data: "denominationTwo",
                edit: false,
                visible: false,
                className: "operate"
            }, {
                title: "营销规则",
                data: "marketRule",
                visible: false,
                className: "operate"
            }, {
                title: "营销结算规则",
                data: "settRule",
                visible: false,
                className: "operate"
            }, {
                title: "电子券状态",
                data: "type2",
                className: "operate",
                options: [
                    {key: "出售、分享、使用",value: "default"},
                    {key: "分享、使用", value: "share"},
                    {key: "使用", value: "useonly"},
                ],
                render: function (data) {
                    var value;
                    if (data == "default") {
                        value = '出售、分享、使用'
                    } else if (data == "share") {
                        value = '分享、使用'
                    } else {
                        value = "使用"
                    }
                    return value;
                }

            }, {
                title: "总数量",
                data: "num",
                edit: true,
                readonly: false,
                className: "operate"
            }, {
                title: "发券途径",
                data: "promAppro",
                className: "operate",
                visible: false,
                options: [
                    {key: "普通券", value: "general"},
                    // {key: "推广券", value: "prom"},
                    // {key: "打赏券", value: "reward"},
                    {key: "购买", value: "buy"},
                ],
                render: function (data) {
                    var value;
                    if (data == "general") {
                        value = '普通券'
                    }else {
                        value = "购买"
                    }
                    return value;
                }
            }, {
                title: "现金",
                data: "cash",
                edit: false,
                visible: false,
                className: "operate"
            }, {
                title: "适用范围",
                visible: false,
                data: "scpoe",
                className: "operate",
                options: [
                    {key: "可用", value: "I"},
                    {key: "不可用", value: "T"}
                ]
            }, {
                title: "适用范围选项",
                visible: false,
                data: "range",
                className: "operate",
            }, {
                title: "已出售数量",
                visible: false,
                data: "soldnum",
                edit: true,
                readonly: true,
                className: "operate"
            }, {
                title: "剩余数量",
                visible: false,
                data: "surplusnum",
                edit: true,
                readonly: true,
                className: "operate"
            }, {
                title: "已使用数量",
                visible: false,
                data: "usednum",
                edit: true,
                readonly: true,
                className: "operate"
            }, {
                title: "未使用数量",
                visible: false,
                data: "unusernum",
                edit: true,
                readonly: true,
                className: "operate"
            },
                {
                    title: "使用规则",
                    visible: false,
                    data: "useRule",
                    className: "operate",
                    checkboxOptions: [{
                        key: "和其他优惠券一起使用",
                        value: "D"
                    }, {
                        key: "叠加使用",
                        value: "M"
                    }]
                }, {
                    title: "叠加张数",
                    visible: false,
                    data: "useNum",
                    edit: false,
                    className: "operate"
                },
                {
                    title: "第三方券类型",
                    visible: false,
                    readonly: true,
                    data: "couponType",
                    className: "operate",
                    options: [{
                        key: "默认",
                        value: "default"
                    }, {
                        key: "第三方",
                        value: "third"
                    }],
                    render: function (data) {
                        var value;
                        if (data == "default") {
                            value = '默认'
                        } else if (data == 'third') {
                            value = '第三方'
                        } else {
                            value = data
                        }
                        return value;
                    }
                },
                {
                    title: "使用描述类型",
                    visible: false,
                    readonly: true,
                    data: "thirdType",
                    className: "operate",
                    options: [{
                        key: "默认",
                        value: "default"
                    }, {
                        key: "链接",
                        value: "url"
                    }],
                    render: function (data) {
                        var value;
                        if (data == "default") {
                            value = '默认'
                        } else if (data == 'url') {
                            value = '链接'
                        } else {
                            value = data
                        }
                        return value;
                    }
                },
                {
                    title: "第三方描述",
                    visible: false,
                    data: "thirdDesc",
                    edit: true,
                    className: "operate"
                },
                {
                    title: "使用开始时间",
                    visible: false,
                    data: "useTime",
                    className: "operate",
                    options: [{
                        key: "00:00",
                        value: "00:00"
                    }, {
                        key: "01:00",
                        value: "01:00"
                    }, {
                        key: "02:00",
                        value: "02:00"
                    }, {
                        key: "03:00",
                        value: "03:00"
                    }, {
                        key: "04:00",
                        value: "04:00"
                    }, {
                        key: "05:00",
                        value: "05:00"
                    }, {
                        key: "06:00",
                        value: "06:00"
                    }, {
                        key: "07:00",
                        value: "07:00"
                    }, {
                        key: "08:00",
                        value: "08:00"
                    }, {
                        key: "09:00",
                        value: "09:00"
                    }, {
                        key: "10:00",
                        value: "10:00"
                    }, {
                        key: "11:00",
                        value: "11:00"
                    }, {
                        key: "12:00",
                        value: "12:00"
                    }, {
                        key: "13:00",
                        value: "13:00"
                    }, {
                        key: "14:00",
                        value: "14:00"
                    }, {
                        key: "15:00",
                        value: "15:00"
                    }, {
                        key: "16:00",
                        value: "16:00"
                    }, {
                        key: "17:00",
                        value: "17:00"
                    }, {
                        key: "18:00",
                        value: "18:00"
                    }, {
                        key: "19:00",
                        value: "19:00"
                    }, {
                        key: "20:00",
                        value: "20:00"
                    }, {
                        key: "21:00",
                        value: "21:00"
                    }, {
                        key: "22:00",
                        value: "22:00"
                    }, {
                        key: "23:00",
                        value: "23:00"
                    }]
                }, {
                    title: "使用结束时间",
                    visible: false,
                    data: "useEndTime",
                    className: "operate",
                    options: [{
                        key: "00:00",
                        value: "00:00"
                    }, {
                        key: "01:00",
                        value: "01:00"
                    }, {
                        key: "02:00",
                        value: "02:00"
                    }, {
                        key: "03:00",
                        value: "03:00"
                    }, {
                        key: "04:00",
                        value: "04:00"
                    }, {
                        key: "05:00",
                        value: "05:00"
                    }, {
                        key: "06:00",
                        value: "06:00"
                    }, {
                        key: "07:00",
                        value: "07:00"
                    }, {
                        key: "08:00",
                        value: "08:00"
                    }, {
                        key: "09:00",
                        value: "09:00"
                    }, {
                        key: "10:00",
                        value: "10:00"
                    }, {
                        key: "11:00",
                        value: "11:00"
                    }, {
                        key: "12:00",
                        value: "12:00"
                    }, {
                        key: "13:00",
                        value: "13:00"
                    }, {
                        key: "14:00",
                        value: "14:00"
                    }, {
                        key: "15:00",
                        value: "15:00"
                    }, {
                        key: "16:00",
                        value: "16:00"
                    }, {
                        key: "17:00",
                        value: "17:00"
                    }, {
                        key: "18:00",
                        value: "18:00"
                    }, {
                        key: "19:00",
                        value: "19:00"
                    }, {
                        key: "20:00",
                        value: "20:00"
                    }, {
                        key: "21:00",
                        value: "21:00"
                    }, {
                        key: "22:00",
                        value: "22:00"
                    }, {
                        key: "23:00",
                        value: "23:00"
                    }]
                }, {
                    title: "使用开始时间2",
                    visible: false,
                    data: "useTime2",
                    className: "operate",
                    options: [{
                        key: " ",
                        value: ""
                    }, {
                        key: "00:00",
                        value: "00:00"
                    }, {
                        key: "01:00",
                        value: "01:00"
                    }, {
                        key: "02:00",
                        value: "02:00"
                    }, {
                        key: "03:00",
                        value: "03:00"
                    }, {
                        key: "04:00",
                        value: "04:00"
                    }, {
                        key: "05:00",
                        value: "05:00"
                    }, {
                        key: "06:00",
                        value: "06:00"
                    }, {
                        key: "07:00",
                        value: "07:00"
                    }, {
                        key: "08:00",
                        value: "08:00"
                    }, {
                        key: "09:00",
                        value: "09:00"
                    }, {
                        key: "10:00",
                        value: "10:00"
                    }, {
                        key: "11:00",
                        value: "11:00"
                    }, {
                        key: "12:00",
                        value: "12:00"
                    }, {
                        key: "13:00",
                        value: "13:00"
                    }, {
                        key: "14:00",
                        value: "14:00"
                    }, {
                        key: "15:00",
                        value: "15:00"
                    }, {
                        key: "16:00",
                        value: "16:00"
                    }, {
                        key: "17:00",
                        value: "17:00"
                    }, {
                        key: "18:00",
                        value: "18:00"
                    }, {
                        key: "19:00",
                        value: "19:00"
                    }, {
                        key: "20:00",
                        value: "20:00"
                    }, {
                        key: "21:00",
                        value: "21:00"
                    }, {
                        key: "22:00",
                        value: "22:00"
                    }, {
                        key: "23:00",
                        value: "23:00"
                    }]
                }, {
                    title: "使用结束时间2",
                    visible: false,
                    data: "useEndTime2",
                    className: "operate",
                    options: [{
                        key: " ",
                        value: ""
                    }, {
                        key: "00:00",
                        value: "00:00"
                    }, {
                        key: "01:00",
                        value: "01:00"
                    }, {
                        key: "02:00",
                        value: "02:00"
                    }, {
                        key: "03:00",
                        value: "03:00"
                    }, {
                        key: "04:00",
                        value: "04:00"
                    }, {
                        key: "05:00",
                        value: "05:00"
                    }, {
                        key: "06:00",
                        value: "06:00"
                    }, {
                        key: "07:00",
                        value: "07:00"
                    }, {
                        key: "08:00",
                        value: "08:00"
                    }, {
                        key: "09:00",
                        value: "09:00"
                    }, {
                        key: "10:00",
                        value: "10:00"
                    }, {
                        key: "11:00",
                        value: "11:00"
                    }, {
                        key: "12:00",
                        value: "12:00"
                    }, {
                        key: "13:00",
                        value: "13:00"
                    }, {
                        key: "14:00",
                        value: "14:00"
                    }, {
                        key: "15:00",
                        value: "15:00"
                    }, {
                        key: "16:00",
                        value: "16:00"
                    }, {
                        key: "17:00",
                        value: "17:00"
                    }, {
                        key: "18:00",
                        value: "18:00"
                    }, {
                        key: "19:00",
                        value: "19:00"
                    }, {
                        key: "20:00",
                        value: "20:00"
                    }, {
                        key: "21:00",
                        value: "21:00"
                    }, {
                        key: "22:00",
                        value: "22:00"
                    }, {
                        key: "23:00",
                        value: "23:00"
                    }]
                }, {
                    title: "不可用日期",
                    data: "disableDate",
                    visible: false,
                    className: "operate",
                    checkboxOptions: [{
                        key: "星期一",
                        value: "1"
                    }, {
                        key: "星期二",
                        value: "2"
                    }, {
                        key: "星期三",
                        value: "3"
                    }, {
                        key: "星期四",
                        value: "4"
                    }, {
                        key: "星期五",
                        value: "5"
                    }, {
                        key: "星期六",
                        value: "6"
                    }, {
                        key: "星期天",
                        value: "7"
                    }]
                }, {
                    title: "有效期开始日期",
                    visible: false,
                    data: "validatyBegin",
                    datetime: true,
                    readonly:true,
                    className: "operate"
                }, {
                    title: "有效期结束日期",
                    // visible: false,
                    data: "validatyEnd",
                    datetime: true,
                    readonly:true,
                    className: "operate",
                    render: function (data) {
                        return dateTransform(data)
                    }
                },
                {
                    title: "相关操作",
                    className: "operate",
                    width: "120px",
                    render: function (value, type, row) {
                        if (row.modFlag != "0" && row.preset == "0") {
                            if (row.status == "1" && row.grantFlag == false) {
                                return `
                                  <button type="button" class="btn btn-danger btn-sm state">开启</button>
                                 `
                            } else if (row.status != "1" && row.grantFlag == false) {
                                //grantFlag=true时授权过
                                return `
                                  <button type="button" class="btn btn-primary btn-sm edit">修改</button>
                                  <button type="button" class="btn btn-defalt btn-sm detail">详情</button>
                                  <button type="button" class="btn btn-danger btn-sm state">关闭</button>
                                  `
                            } else if (row.status != "1" && row.grantFlag == true) {
                                return `
                                  <button type="button" class="btn btn-defalt btn-sm detail">详情</button>
                                  `
                            } else {
                                return `
                                  <button type="button" class="btn btn-primary btn-sm edit">修改</button>
                                  <button type="button" class="btn btn-defalt btn-sm detail">详情</button>
                                  <button type="button" class="btn btn-danger btn-sm state">关闭</button>
                                `
                            }

                        } else {
                            return `
                                 <button type="button" class="btn btn-defalt btn-sm detail">详情</button>
                            `
                        }
                    }
                }];
        },

        ready: async function () {
            var scpoeWatch = function () {
            };
            var typeWatch = function () {
            };
            var useRuleWatch = function () {
            };
            var promWatch = function () {
            };
            var thirdTpeWatch = function () {
            };
            var dateWatch = function () {
            };
            var ranggLethWatch = function () {
            };
            this.$set("columnsSet", columnsSet);
            var self = this;
            self.getMcht();
            //创建dataTable
            dataTable = $(this.$els.table).DataTable({
                "columns": this.columnsSet, //定义列
                "ajax": async function (data, callback, settings) {
                    var page = [{
                        "name": "iDisplayStart",
                        "value": 1 + data.start / data.length
                    }, {
                        "name": "iDisplayLength",
                        "value": data.length
                    }];
                    //表单序列化数据
                    var _data = serialize(self.$els.form, {
                        hash: true,
                        disabled: true,
                        empty: true
                    });
                    _data.aoData = JSON.stringify(page);
                    //发送请求
                    var mchtId = JSON.parse(localStorage.getItem("id_token")).mchtId;
                    var result = await self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/coupon/query/" + mchtId,
                        data: _data,
                        method: "POST"
                    })
                    if (result.respCode != "00") {
                        Midway.alert({
                            title: "操作失败",
                            content: result.content
                        })
                    }
                    callback({
                        recordsTotal: result.content.total || 0,
                        recordsFiltered: result.content.total || 0,
                        data: result.content.couponList || []
                    })
                    //即将过期的优惠券 有效日期显示红色
                    if (result.content.couponList != '' && result.content.couponList != null) {
                        for (var i in result.content.couponList) {
                            // console.log(result.content.couponList[i].expireTime)
                            if (result.content.couponList[i].expireTime == 3) {
                                var trs = $('tbody tr td:nth-child(8)');
                                $(trs[i]).css('color', 'red');

                            }
                        }
                    }

                }
            });

            $(self.$el).on("click", ".edit", function () {
                setTimeout(() =>dateTime({
                    format: "yyyy-mm-dd",
                    minView: "2"
                }),350)
                var Row = $(this).closest('tr').get(0);
                const dataArray = JSON.parse(JSON.stringify(dataTable.row(Row).data()));
                //
                if (dataArray.mchtIds != '') {
                    // self.columnsSet.find(data => data.data == "mchtIds").readonly = true;
                }
                //如果第三方券导入券码 电子券的数量不能修改
                if (dataArray.count == 'true') {
                    self.columnsSet.find(data => data.data == "num").readonly = true;
                }
                //类型是第三方 使用描述类型红星显示
                if (dataArray.couponType == 'third') {
                    self.columnsSet.find(data => data.data == "thirdType").required = true;
                } else {
                    self.columnsSet.find(data => data.data == "thirdType").required = false;
                }
                //类型是第三方 描述红星显示
                if (dataArray.couponType == 'third') {
                    self.columnsSet.find(data => data.data == "thirdDesc").required = true;
                } else {
                    self.columnsSet.find(data => data.data == "thirdDesc").required = false;
                }
                //使用类型是链接 描述只能是url
                if (dataArray.thirdType == 'url') {
                    self.columnsSet.find(data => data.data == "thirdDesc").url = true;
                } else {
                    self.columnsSet.find(data => data.data == "thirdDesc").url = false;
                }
                //面值(折扣)回显
                if (dataArray.type == "rebate") {
                    dataArray.denominationTwo = dataArray.denomination;
                }
                self.item = dataArray;
                dateTime()

                self.mchtIdent = dataArray.mchtIdent;
                //请求可授权数量
                   self.$post({
                          url: "/api/v2" + projectName_Url + "/plat/grant/accreditNum",
                          data: {'mchtId': self.item.mchtId, 'couponId': self.item.couponId},
                          method: "POST"
                   }).then(response => {
                          self.item.surplusnum = response.content.surplusnum;
                   }, error => {
                   });
                if (dataArray.mchtIdent != '4') {
                    //修改弹框里请求适用范围选项
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/dishType/querylow/" + dataArray.mchtId,
                        method: "GET"
                    }).then(response => {
                        let list = response.content.lowTypeNameList;
                        //不可用不能全选
                        let length  = list.length;
                        ranggLethWatch()
                        ranggLethWatch = self.$refs.item.$watch("item.range", function (v) {
                            if(self.scopeTpe == 'T'){
                                if(self.item.range.length > length - 1){
                                    Midway.alert({title: "操作提示", content: "至少选一个可用"})
                                    event.srcElement.checked = false;
                                }
                          }
                        });
                        var _array = [];
                        for (let i = 0; i < list.length; i++) {
                            _array.push({value: list[i].typeId, key: list[i].typeName});
                        }
                        self.rangeArr = _array
                        if (list != "") {
                            self.$set("columnsSet[16].checkboxOptions", _array)
                            // self.columnsSet.find(data => data.data == "range").checkboxOptions =  _array;
                        }
                        return _array
                    }).then(array => {
                        //监控适用范围值变化,重新赋值
                        scpoeWatch()
                        scpoeWatch = self.$refs.item.$watch("item.scpoe", function (v) {
                            self.scopeTpe = v;
                            let set = [];
                            set = array.map(data => {
                                return data.value
                            })
                            let dir = _.difference(set, self.item.range);
                            self.item.range = dir
                        });

                    })
                } else {
                    self.columnsSet.find(data => data.data == "scpoe").options = '';
                    self.columnsSet.find(data => data.data == "range").checkboxOptions = '';
                }

                if (dataArray.mchtIdent != '4') {
                    //修改弹框里适用商户选项
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/mcht/getmchtname/" + dataArray.mchtId,
                        method: "GET"
                    }).then(response => {
                        let list = response.content.info;
                        var _array = [];
                        if (list != "" && list != [] && list != null) {
                            for (let i = 0; i < list.length; i++) {
                                _array.push({value: list[i].mchtId, key: list[i].mchtName});
                            }
                            self.$set("columnsSet[4].checkboxOptions", _array)
                        } else {
                            var _array = '';
                            self.$set("columnsSet[4].checkboxOptions", _array)
                        }
                    }, error => {
                    })
                } else {
                    //修改弹框里适用商圈选项
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/mcht/gettdareamchtname/" + dataArray.mchtId,
                        method: "GET"
                    }).then(response => {
                        let list = response.content.info;
                        var _array = [];
                        if (list != "" && list != [] && list != null) {
                            for (let i = 0; i < list.length; i++) {
                                _array.push({value: list[i].mchtId, key: list[i].mchtName});
                            }
                            self.$set("columnsSet[4].checkboxOptions", _array)
                        } else {
                            var _array = '';
                            self.$set("columnsSet[4].checkboxOptions", _array)
                        }
                    }, error => {
                    })

                }
            
                //修改弹框里请求营销规则
                if(self.item.promAppro != 'buy'){
                    var _data = {
                        couponType: self.item.type,
                        mchtId: self.item.mchtId,
                        denomination: self.item.denomination
                    };
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/rule/listRules",
                        data: _data,
                        method: "post"
                    }).then(response => {
                        let list = response.content.rulesList;
                        let _array = []
                        if (list != '' || list != 'null') {
                            for (var i = 0; i < list.length; i++) {
                                _array.push({value: list[i].value, key: list[i].key})
                            }
                        }
                        _array.push({value: "", key: "无"});
                        self.marketArr = _array;
                        self.columnsSet.find(data => data.data == "marketRule").options = _array;
                    }, error => {
                    });

                    //修改弹框里请求营销结算规则
                    var _data = {
                        couponType: self.item.type,
                        mchtId: self.item.mchtId,
                        denomination: self.item.denomination
                    };
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/rule/listUseRules",
                        data: _data,
                        method: "post"
                    }).then(response => {
                        let list = response.content.rulesList;
                        let _array = []
                        if (list != '' || list != 'null') {
                            for (var i = 0; i < list.length; i++) {
                                _array.push({value: list[i].value, key: list[i].key})
                            }
                        }
                        _array.push({value: "", key: "无"});
                        self.settArr = _array;
                        if (self.item.couponType != 'third' && self.item.promAppro == 'general') {
                            self.$set("columnsSet[10].options", _array)
                            // self.columnsSet.find(data => data.data == "settRule").options = _array;
                        }
                    }, error => {
                    });
                }

                //发券途径  营销规则隐藏
                if (self.item.promAppro == 'buy' || self.item.promAppro == 'prom' || self.item.promAppro == 'reward') {
                    self.columnsSet.find(data => data.data == "marketRule").options = '';
                    self.columnsSet.find(data => data.data == "settRule").options = '';
                } else {
                    self.columnsSet.find(data => data.data == "marketRule").options = self.marketArr;
                    if (self.item.couponType == 'default' && self.item.type != 'present' && self.item.type != 'ticket') {
                        self.$set("columnsSet[10].options", self.settArr)
                        // self.columnsSet.find(data => data.data == "settRule").options = self.settArr;
                    }
                }

                //监听发券途径
                promWatch()
                promWatch = self.$refs.item.$watch("item.promAppro", function (v) {
                    this.promTpe = v;
                    if (v == 'buy') {
                        self.columnsSet.find(data => data.data == "type2").options = [{
                            key: "使用",
                            value: "useonly"
                        }];
                        self.columnsSet.find(data => data.data == "cash").edit = true;
                    } else {
                        if (this.couponType == 'rebate' || this.couponType == 'voucher' || this.couponType == 'cash') {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "出售、分享、使用",
                                value: "default"
                            }, {
                                key: "分享、使用",
                                value: "share"
                            }, {
                                key: "使用",
                                value: "useonly"
                            }];
                        } else {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "分享、使用",
                                value: "share"
                            }, {
                                key: "使用",
                                value: "useonly"
                            }];
                        }
                        self.columnsSet.find(data => data.data == "cash").edit = false;
                    }
                    if (v == 'buy' || v == 'prom' || v == 'reward') {
                        //不能有营销规则
                        self.columnsSet.find(data => data.data == "marketRule").options = '';
                        self.columnsSet.find(data => data.data == "settRule").options = '';
                    } else {
                        self.columnsSet.find(data => data.data == "marketRule").options = self.marketArr;
                        if (self.item.couponType != 'third' && self.item.type != 'present' && self.item.type != 'ticket') {
                            self.columnsSet.find(data => data.data == "settRule").options = self.settArr;
                        }
                    }
                });
                //类型判断 显示隐藏
                typeWatch()
                typeWatch = self.$refs.item.$watch("item.type", function (v) {
                    this.couponType = v;
                    //营销规则下拉列表 传被选中的商户和电子券类型
                    var _data = {couponType: v, mchtId: self.item.mchtId, denomination: self.item.denomination};
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/rule/listRules",
                        data: _data,
                        method: "post"
                    }).then(response => {
                        let list = response.content.rulesList;
                        let _array = []
                        if (list != '' || list != 'null') {
                            for (var i = 0; i < list.length; i++) {
                                _array.push({value: list[i].value, key: list[i].key})
                            }
                        }
                        _array.push({value: "", key: "无"});
                        self.columnsSet.find(data => data.data == "marketRule").options = _array;
                    }, error => {
                    });
                    //营销结算规则下拉列表 传被选中的商户和电子券类型
                    var _data = {couponType: v, mchtId: self.item.mchtId, denomination: self.item.denomination};
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/rule/listUseRules",
                        data: _data,
                        method: "post"
                    }).then(response => {
                        let list = response.content.rulesList;
                        let _array = []
                        if (list != '' || list != 'null') {
                            for (var i = 0; i < list.length; i++) {
                                _array.push({value: list[i].value, key: list[i].key})
                            }
                        }
                        _array.push({value: "", key: "无"});
                        if (self.item.couponType != 'third' && self.item.promAppro != buy) {
                            self.columnsSet.find(data => data.data == "settRule").options = _array;
                        }
                    }, error => {
                    });

                    if (v == "voucher") {
                        self.columnsSet.find(data => data.data == "restricted").edit = true;
                        if (this.promTpe != 'buy') {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "出售、分享、使用",
                                value: "default"
                            }, {
                                key: "分享、使用",
                                value: "share"
                            }, {
                                key: "使用",
                                value: "useonly"
                            }];
                        } else {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "使用",
                                value: "useonly"
                            }];
                        }
                    } else {
                        self.columnsSet.find(data => data.data == "restricted").edit = false;
                    }
                    if (v == "rebate") {
                        self.columnsSet.find(data => data.data == "denominationTwo").edit = true;
                        self.columnsSet.find(data => data.data == "denomination").edit = false;
                        self.columnsSet.find(data => data.data == "useRule").checkboxOptions = '';
                        self.columnsSet.find(data => data.data == "useNum").edit = false;
                        if (this.promTpe != 'buy') {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "出售、分享、使用",
                                value: "default"
                            }, {
                                key: "分享、使用",
                                value: "share"
                            }, {
                                key: "使用",
                                value: "useonly"
                            }];
                        } else {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "使用",
                                value: "useonly"
                            }];
                        }
                    } else {
                        self.columnsSet.find(data => data.data == "denominationTwo").edit = false;
                        self.columnsSet.find(data => data.data == "denomination").edit = true;
                        self.columnsSet.find(data => data.data == "useRule").checkboxOptions = [{
                            key: "和其他优惠券一起使用",
                            value: "D"
                        }, {
                            key: "叠加使用",
                            value: "M"
                        }];
                    }

                    if (v == "cash") {
                        self.columnsSet.find(data => data.data == "denominationTwo").edit = false;
                        self.columnsSet.find(data => data.data == "denomination").edit = true;
                        if (this.promTpe != 'buy') {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "出售、分享、使用",
                                value: "default"
                            }, {
                                key: "分享、使用",
                                value: "share"
                            }, {
                                key: "使用",
                                value: "useonly"
                            }];
                        } else {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "使用",
                                value: "useonly"
                            }];
                        }
                    }
                    if (v == "present" || v == 'ticket') {
                        $(".modal-body tbody tr:nth-child(11)").css('display', 'none');
                        self.columnsSet.find(data => data.data == "useRule").checkboxOptions = '';
                        if (this.promTpe != 'buy') {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "分享、使用",
                                value: "share"
                            }, {
                                key: "使用",
                                value: "useonly"
                            }];
                        } else {
                            self.columnsSet.find(data => data.data == "type2").options = [{
                                key: "使用",
                                value: "useonly"
                            }];
                        }
                        self.columnsSet.find(data => data.data == "scpoe").options = '';
                        self.columnsSet.find(data => data.data == "scpoe").required = false;
                        self.columnsSet.find(data => data.data == "range").checkboxOptions = '';
                        self.columnsSet.find(data => data.data == "range").required = false;
                    } else {
                        if (self.item.couponType != 'third' && self.item.promAppro == 'general') {
                            $(".modal-body tbody tr:nth-child(11)").css('display', '');
                        }
                        self.$set("columnsSet[16].checkboxOptions", self.rangeArr)
                        // self.columnsSet.find(data => data.data == "range").checkboxOptions = self.rangeArr;
                        if (dataArray.mchtIdent != '4') {
                            self.columnsSet.find(data => data.data == "scpoe").options = [{
                                key: "可用",
                                value: "I"
                            }, {
                                key: "不可用",
                                value: "T"
                            }];
                            self.columnsSet.find(data => data.data == "scpoe").required = true;
                            self.columnsSet.find(data => data.data == "range").required = true;
                        }
                    }
                });
                //点击叠加使用  叠加张数显示
                useRuleWatch()
                useRuleWatch = self.$refs.item.$watch("item.useRule", function (v) {
                    if (v == 'M' || v == 'D,M' || v == 'M,D') {
                        self.columnsSet.find(data => data.data == "useNum").edit = true;
                    } else {
                        self.columnsSet.find(data => data.data == "useNum").edit = false;
                    }
                });

                //第三方券 描述限制字数
                thirdTpeWatch()
                thirdTpeWatch = self.$refs.item.$watch("item.couponType", function (v) {
                    if (v == 'third') {
                        $(self.$els.mform.thirdDesc).rules("add", {
                            required:true,
                            maxlength: 300
                        });
                    } else {
                        $(self.$els.mform.thirdDesc).rules("remove", "required");
                        $(self.$els.mform.thirdDesc).rules("remove", "maxlength");
                    }
                });

                //不可用日期
                dateWatch()
                dateWatch = self.$refs.item.$watch("item.disableDate", function (v) {
                    if (self.item.disableDate.length > 6) {
                        Midway.alert({title: "操作提示", content: "电子券使用日期至少有一天可用"})
                        event.srcElement.checked = false;
                    }
                });

                //适用范围回显
                var _arr = dataArray.scpoe;
                var scope = $.trim(_arr[0]);
                self.item.scpoe = scope

                var _newArr = _arr.slice(1, _arr.length + 1);
                var a = _newArr.split(",");
                var _checkedRangeArr = [];
                for (var i = 0; i < a.length; i++) {
                    _checkedRangeArr.push(parseInt(a[i]))
                }
                self.item.range = _checkedRangeArr

                //适用商户回显
                var _mchtsArr = dataArray.mchtIds;
                var b = _mchtsArr.split(",");
                var _checkedMchtsArr = [];
                for (var i = 0; i < b.length; i++) {
                    _checkedMchtsArr.push(parseInt(b[i]))
                }
                self.item.mchtIds = _checkedMchtsArr
                if (dataArray.mchtIdent != '4') {
                    //除了适用商圈  已添加的适用商户不可取消
                    $(function () {
                        $("input:checkbox[name='mchtIds']:checked").each(function () { // 遍历name=mchtIds的多选框
                            $(this).prop('disabled', true); // 每一个被选中项的值
                        });
                    })
                }

                //使用规则回显
                var _set = new Set(dataArray.useRule);
                var _arrRule = Array.from(_set);
                let checkedRuleArr = []
                _arrRule.forEach((item, index) => {
                    if (item) {
                        checkedRuleArr.push(item)
                    }
                })
                self.item.useRule = checkedRuleArr

                //使用时间段回显
                var list = dataArray.useTime.split(",");
                var tmp = $.trim(list[0]);
                var _str = tmp.split("-");
                dataArray.useTime = $.trim(_str[0]);
                dataArray.useEndTime = $.trim(_str[1]);

                var tmp2 = $.trim(list[1]);
                var _str2 = tmp2.split("-");
                if (dataArray.useTime2 != '' && dataArray.useTime2 != '') {
                    dataArray.useTime2 = $.trim(_str2[0]);
                    dataArray.useEndTime2 = $.trim(_str2[1]);
                }

                //不可用日期回显
                var _set = new Set(dataArray.disableDate);
                if (_set.has(",")) {
                    _set.delete(",");
                }
                var _arrDay = Array.from(_set);
                let checkedDayArr = []
                _arrDay.forEach((item, index) => {
                    checkedDayArr.push(self.disableDay[item - 1].value)
                })
                self.item.disableDate = checkedDayArr

                //编辑框验证、保存、提交
                $(self.$els.mform).validate(self.item.valdate = {
                    async submitHandler () {
                        var form = self.$els.mform;
                        var _data = serialize(form, {hash: true, disabled: true, empty: true});
                        //适用范围数据处理
                        if (_data.type == 'present' || _data.type == 'ticket') {
                            _data.scpoe = 'I';
                        } else {
                            if (_data.scpoe != '' && _data.scpoe != null) {
                                var _arr = _data.scpoe;
                                var first = _arr[0];
                                var _newArr = '';
                                $("input[name=range]").each(function () {
                                    if ($(this).is(":checked")) {
                                        _newArr += $(this).val() + ",";
                                    }
                                });
                                _newArr = _newArr.substr(0, _newArr.length - 1).split(",").join(",");
                                _data.scpoe = first + _newArr;
                            }
                        }
                        //类型不是buy的时候，cash默认传0
                        if (_data.promAppro != 'buy') {
                            _data.cash = 0;
                        }
                        //发券途径不是普通券的时候，marketRule默认传空
                        if (_data.promAppro != 'general') {
                            _data.marketRule = '';
                            _data.settRule = '';
                        }
                        //类型是礼品券和门票,settRule默认传空
                        if (_data.type == 'present' || _data.type == 'ticket') {
                            _data.settRule = '';
                        }
                        //抵用券金额与面值验证
                        if (_data.type == 'voucher') {
                            if (Number(_data.denomination) > Number(_data.restricted)) {
                                Midway.alert({title: "操作提示", content: '面值应小于抵用券金额'})
                                return false
                            } else {

                            }
                            ;
                        }

                        //适用商户数据处理
                        var _arr = _data.mchtIds;
                        var _mchtsArr = '';
                        $("input[name=mchtIds]").each(function () {
                            if ($(this).is(":checked")) {
                                _mchtsArr += $(this).val() + ",";
                            }
                        });
                        _mchtsArr = _mchtsArr.substr(0, _mchtsArr.length - 1).split(",").join(",")
                        _data.mchtIds = _mchtsArr;

                        //使用规则 数据处理
                        var useRule = [];
                        for (var key in _data.useRule) {
                            if (_data.useRule[key]) {
                                useRule.push(_data.useRule[key]);
                            }
                        }
                        delete _data.useRule;
                        _data.useRule = useRule.join("");

                        //useTime进行数据处理
                        if ($("select[name='useTime']").val() == "00:00" && $("select[name='useEndTime']").val() == "00:00") {
                            Midway.alert({title: "操作提示", content: '使用时间段不能都为00:00'})
                            return false
                        } else {
                            var useTime = $("select[name='useTime']").val() + '-' + $("select[name='useEndTime']").val();
                            //判断营业时间段2
                            if ($("select[name='useTime2']").val() == '' && $("select[name='useEndTime2']").val() == '') {
                                _data.useTime = useTime
                            } else if ($("select[name='useTime2']").val() != '' && $("select[name='useEndTime2']").val() != '') {
                                if ($("select[name='useTime2']").val() == "00:00" && $("select[name='useEndTime2']").val() == "00:00") {
                                    Midway.alert({title: "操作提示", content: '使用时间段2不能都为00:00'})
                                    return false
                                } else if ($("select[name='useTime2']").val() >= $("select[name='useEndTime2']").val()) {
                                    Midway.alert({title: "操作提示", content: '使用时间段2:开始时间不能大于等于结束时间'})
                                    return false
                                } else {
                                    var useTime2 = $("select[name='useTime2']").val() + '-' + $("select[name='useEndTime2']").val();
                                    _data.useTime = useTime + ',' + useTime2;
                                }
                            } else {
                                $("select[name='useTime2']").val() != '' && $("select[name='useEndTime2']").val() != '';
                                Midway.alert({title: "操作提示", content: '使用时间段2需填写完整'})
                                return false
                            }

                        }
                        //判断两个时间段不能重合
                        var y = $("select[name='useEndTime']").val();
                        var a = $("select[name='useTime2']").val();
                        var b = $("select[name='useEndTime2']").val();
                        var x = $("select[name='useTime']").val();
                        if (y <= a || b <= x) {
                        } else {
                            Midway.alert({title: "操作提示", content: '两个时间段不能有重合'})
                            return false
                        }
                        ;
                        //对有效起始结束日期进行数据处理
                        //  _data.validatyBegin = _data.validatyBegin.replace(/\s|-|:/g,'');
                        //  _data.validatyEnd = _data.validatyEnd.replace(/\s|-|:/g,'');
                        _data.validatyBegin = _data.validatyBegin.replace(/-|:|\s/g, '');
                        _data.validatyEnd = _data.validatyEnd.replace(/-|:|\s/g, '');

                        // //判断电子券有效期不低于一天
                        // if (_data.promAppro != 'buy' && _data.cash != '0') {
                        //     var lastData = _data.validatyEnd - _data.validatyBegin;
                        //     var time = 1;
                        //     if (_data.validatyBegin.length > 0 && _data.validatyEnd.length > 0) {
                        //         if (lastData < 0 || lastData < time) {
                        //             Midway.alert({title: "操作提示", content: '有效开始和有效结束日期相差不低于一天'})
                        //             return false
                        //         }
                        //     }
                        // }

                        //进行不可使用日期的数据处理
                        var disableDate = [];
                        for (var key in _data.disableDate) {
                            if (_data.disableDate[key]) {
                                disableDate.push(_data.disableDate[key]);
                            }
                        }
                        delete _data.disableDate;
                        _data.disableDate = disableDate.join(",");

                        if (_data.type == "rebate") {
                            _data.denomination = _data.denominationTwo;
                        } else {
                            _data.denomination = _data.denomination;
                        }
                        //商圈商户的时候直接传I
                        if (dataArray.mchtIdent == '4') {
                            _data.scpoe = 'I';
                        }
                        _data.mchtId = self.item.mchtId;
                        var result = await self.$post({
                            url: "/api/v2" + projectName_Url + "/plat/coupon/" + _data.couponId,
                            data: _data,
                            method: "PUT"
                        });
                        Midway.alert({title: "操作提示", content: result.errorInfo});
                        if (_data.type2 == 'useonly' && _data.marketRule != '') {
                            Midway.alert({title: "操作提示", content: '该电子券不可分享，分享奖励的钱会返还给商户'});
                        }
                        dataTable.ajax.reload(null, false);
                        $(self.$els.modal).modal('hide');
                        self.resetBindDrag()
                    },
                    errorPlacement: function (error, element) {
                        if (element.attr("name") == "range") {
                            error.insertAfter(element.parents("div.checkbox-item"));
                        } else {
                            error.insertAfter(element)
                        }
                    },
                    rules: {
                        mchtId: {
                            required: true
                        },
                        mchtName: {
                            required: true
                        },
                        couponId: {
                            required: true
                        },
                        name: {
                            required: true,
                            maxlength: 32
                        },
                        type: {
                            required: true
                        },
                        type2: {
                            required: true
                        },
                        denomination: {
                            required: true,
                            number: true,
                            int: true,
                            min: 1,
                            max: 9999
                        },
                        denominationTwo: {
                            required: true,
                            number: true,
                            int: true,
                            min: 1,
                            max: 99
                        },
                        restricted: {
                            required: true,
                            int: true,
                            min: 1
                        },
                        num: {
                            required: true,
                            number: true,
                            int: true,
                            min: 1,
                            max: 9999
                        },
                        promAppro: {
                            required: true
                        },
                        cash: {
                            cash: true
                        },
                        scpoe: {
                            required: true
                        },
                        per: {
                            number: true,
                            min: 1
                        },
                        useNum: {
                            required: true,
                            min: 1,
                            max: 3,
                            int: true
                        },
                        range: {
                            required: false
                        },
                        soldnum: {
                            required: true
                        },
                        surplusnum: {
                            required: true
                        },
                        usednum: {
                            required: true
                        },
                        unusernum: {
                            required: true
                        },
                        useTime: {
                            required: true,
                            comparisonSize: ["useTime", "useEndTime"]
                        },
                        useEndTime: {
                            required: true,
                            comparisonSize: ["useTime", "useEndTime"]
                        },
//                        useTime2: {
//                            comparisonSize: ["useTime2", "useEndTime2"]
//                        },
//                        useEndTime2: {
//                            comparisonSize: ["useTime2", "useEndTime2"]
//                        },
                        validatyBegin: {
                            required: true,
                            compareDate: ["validatyBegin", "validatyEnd"]
                        },
                        validatyEnd: {
                            required: true,
                            compareDate: ["validatyBegin", "validatyEnd"]
                        }
                    }
                });
                $(self.$els.modal).modal('show');
            });
            $(self.$el).on("click", ".detail", function () {
                var Row = $(this).closest('tr').get(0);
                const dataArray = JSON.parse(JSON.stringify(dataTable.row(Row).data()));
                self.item = dataArray;
                dataArray.validatyBegin = dateTransform(dataArray.validatyBegin);
                dataArray.validatyEnd = dateTransform(dataArray.validatyEnd);
                dateTime()
                //详情弹框里请求已授权数量
                _data = {grantMcht: dataArray.mchtId, couponId: dataArray.couponId};
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/grant/getIssuedNum",
                    data: _data,
                    method: "POST"
                }).then(response => {
                    let issuedNum = response.content.issuedNum;
                    self.issuedNum = issuedNum;
                }, error => {
                });
                //详情弹框里请求适用范围选项
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/dishType/querylow/" + dataArray.mchtId,
                    method: "GET"
                }).then(response => {
                    let list = response.content.lowTypeNameList;
                    //对适用范围进行数据处理
                    let _arr = self.item.scpoe;
                    dataArray.scpoe = $.trim(_arr[0]);
                    if (dataArray.scpoe == "I") {
                        self.scpoe = "可用:";
                    } else {
                        self.scpoe = "不可用:";
                    }
                    var _newArr = _arr.slice(1, _arr.length + 1);
                    var _rangeArr = _newArr.split(",");
                    var _checkedRange = [];
                    for (var i = 0; i < _rangeArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].typeId) == parseInt(_rangeArr[i])) {
                                _checkedRange.push(list[k].typeName);
                            }
                        }
                    }
                    if (dataArray.mchtIdent != '4') {
                        self.scpoe += _checkedRange.join(",") || '无';
                    } else {
                        self.scpoe = '';
                    }
                }, error => {
                });
                //详情弹框里适用商户选项
                if (dataArray.mchtIdent != '4') {
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/mcht/getmchtname/" + dataArray.mchtId,
                        method: "GET"
                    }).then(response => {
                        let list = response.content.info;
                        //对适用商户进行数据处理
                        let _arr = self.item.mchtIds;
                        var _mchtsArr = _arr.split(",");
                        var _checkedMchts = [];
                        for (var i = 0; i < _mchtsArr.length; i++) {
                            for (var k = 0; k < list.length; k++) {
                                if (parseInt(list[k].mchtId) == parseInt(_mchtsArr[i])) {
                                    _checkedMchts.push(list[k].mchtName);
                                }
                            }
                        }
                        self.item.mchtIds = _checkedMchts.join(",") || '无';
                    }, error => {
                    })
                } else {
                    self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/mcht/gettdareamchtname/" + dataArray.mchtId,
                        method: "GET"
                    }).then(response => {
                        let list = response.content.info;
                        //对适用商户进行数据处理
                        let _arr = self.item.mchtIds;
                        var _mchtsArr = _arr.split(",");
                        var _checkedMchts = [];
                        for (var i = 0; i < _mchtsArr.length; i++) {
                            for (var k = 0; k < list.length; k++) {
                                if (parseInt(list[k].mchtId) == parseInt(_mchtsArr[i])) {
                                    _checkedMchts.push(list[k].mchtName);
                                }
                            }
                        }
                        self.item.mchtIds = _checkedMchts.join(",") || '无';
                    }, error => {
                    })

                }

                   //请求可授权数量
                   self.$post({
                          url: "/api/v2" + projectName_Url + "/plat/grant/accreditNum",
                          data: {'mchtId': self.item.mchtId, 'couponId': self.item.couponId},
                          method: "POST"
                   }).then(response => {
                          self.surplusnum = response.content.surplusnum;
                   }, error => {
                   });
                //详情弹框里营销规则选项
                var _data = {couponType: self.item.type, mchtId: self.item.mchtId};
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/rule/list",
                    data: _data,
                    method: "post"
                }).then(response => {
                    let list = response.content.rulesList;
                    let _array = self.item.marketRule;
                    let _ruleArr = _array.split(',')
                    let __checkedRules = [];
                    for (var i = 0; i < _ruleArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].value) == parseInt(_ruleArr[i])) {
                                __checkedRules.push(list[k].key);
                            }
                        }
                    }
                    self.item.marketRule = __checkedRules.join(",") || '无';
                }, error => {
                });

                //详情弹框里营销结算规则选项
                var _data = {couponType: self.item.type, mchtId: self.item.mchtId};
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/rule/listUseRules",
                    data: _data,
                    method: "post"
                }).then(response => {
                    let list = response.content.rulesList;
                    let _array = self.item.settRule;
                    let _ruleArr = _array.split(',')
                    let __checkedRules = [];
                    for (var i = 0; i < _ruleArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].value) == parseInt(_ruleArr[i])) {
                                __checkedRules.push(list[k].key);
                            }
                        }
                    }
                    self.item.settRule = __checkedRules.join(",") || '无';
                }, error => {
                });

                //详情弹框里授权商户选项
                self.$post({
                    url: "/api/v2" + projectName_Url + "/list/mcht/agent",
                    method: "POST"
                }).then(response => {
                    let list = response.content.list;
                    let _array = self.item.grantMerchant;
                    let _grantArr = _array.split(',')
                    let __checkedGrantMcht = [];
                    for (var i = 0; i < _grantArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].key) == parseInt(_grantArr[i])) {
                                __checkedGrantMcht.push(list[k].value);
                            }
                        }
                    }
                    self.item.grantMerchant = __checkedGrantMcht.join(",") || '无';
                });

                //处理使用日期多选数据
                let _myArray = self.item.disableDate.split(",");
                let _myStr = '';
                let set = new Set();
                _myArray.forEach(s => set.add(s));
                if (set.has("1")) {
                    _myStr += "星期一" + " "
                }
                if (set.has("2")) {
                    _myStr += "星期二" + " "
                }
                if (set.has("3")) {
                    _myStr += "星期三" + " "
                }
                if (set.has("4")) {
                    _myStr += "星期四" + " "
                }
                if (set.has("5")) {
                    _myStr += "星期五" + " "
                }
                if (set.has("6")) {
                    _myStr += "星期六" + " "
                }
                if (set.has("7")) {
                    _myStr += "星期日" + " "
                }
                self.disableDate = _myStr;

                //对使用规则进行数据处理
                let _useRule = ["和其他优惠券一起使用", "叠加使用"];
                let _myArr = self.item.useRule.split(",");
                let _str = '';
                let mySet = new Set();
                _myArr.forEach(s => mySet.add(s));
                if (mySet.has("D")) {
                    _str += "和其他优惠券一起使用" + " "
                }
                if (mySet.has("M")) {
                    _str += "叠加使用" + " "
                }
                if (mySet.has("DM")) {
                    _str += "和其他优惠券一起使用," + "叠加使用" + " "
                }
                self.useRule = _str;

                $(self.$els.detailModal).modal('show');
            });

            $(self.$el).on("click", ".state", async function () {
                var Row = $(this).closest('tr').get(0);
                var value = dataTable.row(Row).data().name;
                var couponId = dataTable.row(Row).data().couponId;
                var mchtId = dataTable.row(Row).data().mchtId;
                let state = dataTable.row(Row).data().status == "0" ? '1' : '0';
                let _data = {
                    mchtId: mchtId,
                    status: state
                }

                if (state == "0") {
                    await Midway.confirm({
                        title: "开启电子券",
                        content: "确认是否要开启:" + value + "?"
                    })
                } else {
                    await Midway.confirm({
                        title: "关闭电子券",
                        content: "确认是否要关闭:" + value + "?"
                    })
                }

                var result = await self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/coupon/status/" + couponId,
                    data: _data,
                    method: "post"
                });
                dataTable.ajax.reload();
            });
        },
        beforeDestroy () {
            $(this.$el).off("click")
        }
    }
</script>
